<%@page import="it.crosato.stage.shared.objects.EntityDefinition"%>
<%@page import="it.crosato.stage.shared.objects.Pathway"%>
<%@page import="java.util.Vector"%>
<html>

<head>
	<title>CoMeta - Dettagli vie metaboliche</title>
	<link type="text/css" rel="stylesheet" href="css/web.css" media="screen" />
	<script type="text/javascript">
	window.onload=function(){
		change();
	};
	function change() {
		var path = document.getElementById("path");
		var org = document.getElementById("org");
		var id = org.options[org.selectedIndex].value + path.options[path.selectedIndex].value;
		var divs = document.getElementsByName("pathway");
		for(var i=0; i < divs.length; i++) {
			divs[i].style.display="none";
		}
		document.getElementById(id).style.display="block";
	}
	</script>
</head>

<body>

	<div class="app">

	<div class="title">
		<h1>CoMeta</h1>
	</div>
	
	<div class="content">
	
		<div class="side">
			<form action="selection.html" method="get">
				<%long time = Long.class.cast(session.getAttribute("time")); %>
				<input type="hidden" name="time" value="<%out.print(time);%>">
				<input type="image" src="pics/freccia-sx.png">
			</form>
		</div>
		
		<div class=result>
			<div class="navigation">
				<ul>
				    <li id="activelink"><a href="pathways.html">Vie metaboliche</a></li>
					<li><a href="sets.html">Insiemi</a></li>
					<li><a href="invariants.html">Reti di Petri</a></li>
					<li><a href="mapping.html">Matrici distanza</a></li>
				    <li><a href="tree.html">Albero filogenetico</a></li>
				</ul>
			</div>
			<div class="resultBox">
				<% 	Boolean error = Boolean.class.cast(request.getAttribute("error"));
					if (!error) {
						@SuppressWarnings("unchecked")
						Vector<String> nonExistentPathways = (Vector<String>)session.getAttribute("nonExistentPathways");
						if (nonExistentPathways.size() != 0) {
							out.println("Le seguenti vie metaboliche non sono presenti in KEGG:<br />");
							for (int i = 0; i < nonExistentPathways.size(); i++) {
								out.println(nonExistentPathways.get(i) + "<br />");
							}
						} else {
							@SuppressWarnings("unchecked")
							Vector<EntityDefinition> selectedOrganisms = (Vector<EntityDefinition>)
								session.getAttribute("selectedOrganisms");
							@SuppressWarnings("unchecked")
							Vector<EntityDefinition> selectedPathways = (Vector<EntityDefinition>)
								session.getAttribute("selectedPathways");
							Pathway[][] pathways = Pathway[][].class.cast(session.getAttribute("pathways"));
							out.println("<div class=\"treeType\">");
							out.println("<select id=\"path\" onChange=\"javascript:change()\">");
							for (int j = 0; j < selectedPathways.size(); j++) {
								out.println("<option>" + selectedPathways.get(j).getDescription() + "</option>");
							}
							out.println("</select>");
							out.println("<select id=\"org\" onChange=\"javascript:change()\">");
							for (int i = 0; i < selectedOrganisms.size(); i++) {
								out.println("<option>" + selectedOrganisms.get(i).getDescription() + "</option>");
							}
							out.println("</select>");
							out.println("</div>");
							for (int j = 0; j < selectedPathways.size(); j++) {
								for (int i = 0; i < selectedOrganisms.size(); i++) {
									String id = selectedOrganisms.get(i).getDescription() + selectedPathways.get(j).getDescription();
									out.println("<div class=\"pathway\" name=\"pathway\"id=\"" + id + "\">");
									Pathway path = pathways[i][j];
									out.println("<img src=\"" + path.getUrl() + "\"/>");
									out.println("</div>");
								}
							}
						}
					} else { %>
						Si sino verificati dei problemi nel recupero delle vie metaboliche. 
						<a href="pathways.html">Riprova</a>
				<% 	} %>
			</div>
		</div>
		
	</div>
	
	<div class="footer">
		<span>Strumento per la comparazione di reti metaboliche</span>
	</div>
	
	</div>

</body>

</html>